package org.louie.hypercube;

import org.lwjgl.opengl.GL11;

public class Cube3D {
    private float angle = 0.0f;
    float[][] cubeVertices = {
            {-0.5f, -0.5f, -0.5f}, {0.5f, -0.5f, -0.5f}, {0.5f, 0.5f, -0.5f}, {-0.5f, 0.5f, -0.5f},  // 后面 4 个点
            {-0.5f, -0.5f, 0.5f}, {0.5f, -0.5f, 0.5f}, {0.5f, 0.5f, 0.5f}, {-0.5f, 0.5f, 0.5f}   // 前面 4 个点
    };

    private void drawCube() {
        GL11.glBegin(GL11.GL_LINES);
        GL11.glColor3f(1.0f, 1.0f, 1.0f); // 线条颜色（白色）

        int[][] edges = {
                {0, 1}, {1, 2}, {2, 3}, {3, 0}, // 后面
                {4, 5}, {5, 6}, {6, 7}, {7, 4}, // 前面
                {0, 4}, {1, 5}, {2, 6}, {3, 7}  // 连接前后
        };

        for (int[] edge : edges) {
            GL11.glVertex3f(cubeVertices[edge[0]][0], cubeVertices[edge[0]][1], cubeVertices[edge[0]][2]);
            GL11.glVertex3f(cubeVertices[edge[1]][0], cubeVertices[edge[1]][1], cubeVertices[edge[1]][2]);
        }

        GL11.glEnd();
    }



    public void drawRotatingCube() {
        GL11.glPushMatrix();
        GL11.glRotatef(angle, 1.0f, 1.0f, 0.0f); // 旋转

        drawCube(); // 调用上面画立方体的方法

        GL11.glPopMatrix();
        angle += 1.0f; // 让它每一帧都旋转一点
    }
}
